import { formatDate } from '../utils';

// user

const schedulesList = [
  {
    title: 'Lorem ipsum dolor sit amet.'
  },
  {
    title: 'Lorem ipsum dolor.'
  },
  {
    title: 'Lorem ipsum dolor.'
  },
  {
    title: 'Lorem ipsum dolor.'
  }
];

const schedules: any[] = [];

for (let index = 0; index < schedulesList.length; index++) {
  let item = schedulesList[index];

  let schedule = {
    date: formatDate(new Date(), 'yyyy-MM-dd'),
    title: item.title
  };
  schedules.push(schedule);
}

export const getSchedules = (): Promise<any> => {
  return new Promise<any>((resolve) => {
    setTimeout(() => {
      resolve({
        data: schedules
      });
    }, 500);
  });
};

export const addSchedules = (params): Promise<any> => {
  return new Promise<void>((resolve) => {
    setTimeout(() => {
      let schedule = {
        date: formatDate(params.date, 'yyyy-MM-dd'),
        content: params.content,
        title: params.title
      };
      schedules.push(schedule);
      resolve();
    }, 500);
  });
};
